﻿using UnityEngine;
using System.Collections;

public class changePlayer : MonoBehaviour {

    public GameObject player;
   

    private  Animator anim;
    public Sprite p0;
    public Sprite p1;
    public Sprite p2;
    public RuntimeAnimatorController r0;
    public RuntimeAnimatorController r1;
    public RuntimeAnimatorController r2;

    private SpriteRenderer sr;
    
    int index = 0;

	void Start () {
        anim = player.GetComponent<Animator>();
        sr = player.GetComponent<SpriteRenderer>();
       // anim.runtimeAnimatorController = Resources.Load("timberman_0_3") as RuntimeAnimatorController;
	}
	
	// Update is called once per frame

    public void Click() 
    {
        if (playerPrefer.haoping==1&&playerPrefer.guanggao==1)//标识解锁全部角色
        {
            index++;
            if (index==3)
            {
                index = 0;
            } 
            if (index==0)
            {
                sr.sprite = p0;
                anim.runtimeAnimatorController = r0;
           
             //   print(sr.sprite.name);
               // print("0");
            }
            else if (index == 1)
            {
                sr.sprite = p1;
                anim.runtimeAnimatorController = r1;
            
              //  print(sr.sprite.name);
             ///   print("1");
            }
            else if (index == 2)
            {
                sr.sprite = p2;
                anim.runtimeAnimatorController = r2;
            
              //  print(sr.sprite.name);
              //  print("2");
            }
        }
        else if (playerPrefer.haoping == 1 && playerPrefer.guanggao != 1)//仅解锁红蓝
        {
            index++;
            if (index == 2)
            {
                index = 0;
            }
            if (index == 0)
            {
                sr.sprite = p0;
                anim.runtimeAnimatorController = r0;

             //   print(sr.sprite.name);
                // print("0");
            }
            else if (index == 1)
            {
                sr.sprite = p1;
                anim.runtimeAnimatorController = r1;

               // print(sr.sprite.name);
                ///   print("1");
            }
        }
        else if (playerPrefer.haoping != 1 && playerPrefer.guanggao == 1)//仅解锁红黄
        {
            index++;
            if (index == 2)
            {
                index = 0;
            }
            if (index == 0)
            {
                sr.sprite = p0;
                anim.runtimeAnimatorController = r0;

              // print("0");
            }
            else if (index == 1)
            {
                sr.sprite = p2;
                anim.runtimeAnimatorController = r2;

               // print(sr.sprite.name);
                ///   print("1");
            }
        }
    }
}
